import express from 'express'
import Mock from 'mockjs'
import cors from 'cors'
import morgan from 'morgan'

let app = express()

// app.use(cors())
app.use(morgan('tiny'))

app.get('/getUser', (req, res) => {
  let data = Mock.mock({
    id: '@id',
    username: '@string("123456789abcdefghuritoplhb",8)',
  })
  res.json(data)
})

app.get('/content', (req, res) => {
  let resData = []
  for (var i = 1; i <= 100; i++) {
    let data = Mock.mock({
      id: '@id',
      title: '@ctitle',
      email: Mock.Random.email(),
      date: Mock.Random.datetime('yyyy-MM-dd'),
      username: '@cname',
      isDone: '@boolean',
      zipcode: /\d{6}/,
      ip: '@ip',
      province: '@province',
      address: '@city(true)',
      country: '@county(true)',
      color: Mock.Random.color(),
      city: '@city',
      content: '@cparagraph',
      create_date: '@datetime',
    })
    resData.push(data)
  }
  res.json(resData)
})

app.listen(5000, () => console.log('api server is running at port 5000'))
